package com.hspedu.set_;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Objects;

/**
 * @author DL5O
 * @version 1.0
 */
public class HashSetExercise01 {
    public static void main(String[] args) {
        HashSet hashSet = new HashSet();
        Employee01 employee01 = new Employee01("ywl", 5000, new MyDate(2000, 9, 9));
        Employee01 employee02 = new Employee01("tom", 2500, new MyDate(2000, 8, 8));
        Employee01 employee03 = new Employee01("tom", 2500, new MyDate(2000, 11, 11));
        Employee01 employee04 = new Employee01("jack", 2500, new MyDate(2000, 9, 9));
        hashSet.add(employee01);
        hashSet.add(employee02);
        hashSet.add(employee03);
        hashSet.add(employee04);

        Iterator iterator = hashSet.iterator();
        while (iterator.hasNext()) {
            Object next = iterator.next();
            System.out.println(next);
        }

    }
}

class MyDate {
    int year;
    int mouth;
    int day;

    public MyDate(int year, int mouth, int day) {
        this.year = year;
        this.mouth = mouth;
        this.day = day;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMouth() {
        return mouth;
    }

    public void setMouth(int mouth) {
        this.mouth = mouth;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MyDate myDate = (MyDate) o;
        return year == myDate.year &&
                mouth == myDate.mouth &&
                day == myDate.day;
    }

    @Override
    public int hashCode() {
        return Objects.hash(year, mouth, day);
    }

    @Override
    public String toString() {
        return this.year + "年" + this.mouth + "月" + this.day + "日";
    }
}


class Employee01 {
    private String name;
    private double sal;
    private MyDate birthday;


    public Employee01(String name, double sal, MyDate birthday) {
        this.name = name;
        this.sal = sal;
        this.birthday = birthday;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Employee01 that = (Employee01) o;
        return Double.compare(that.sal, sal) == 0 &&
                Objects.equals(name, that.name) &&
                Objects.equals(birthday, that.birthday);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, sal, birthday);
    }

    @Override
    public String toString() {
        return "Employee01{" +
                "name='" + name + '\'' +
                ", sal=" + sal +
                ", birthday=" + birthday +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSal() {
        return sal;
    }

    public void setSal(double sal) {
        this.sal = sal;
    }

    public MyDate getBirthday() {
        return birthday;
    }

    public void setBirthday(MyDate birthday) {
        this.birthday = birthday;
    }
}

